﻿// Decompiled with JetBrains decompiler
// Type: TaleWorlds.CampaignSystem.Settlements.Locations.AccompanyingCharacter
// Assembly: TaleWorlds.CampaignSystem, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E85F8C15-4DF6-4E9C-A58A-29177E40D07A
// Assembly location: D:\steam\steamapps\common\Mount & Blade II Bannerlord\bin\Win64_Shipping_Client\TaleWorlds.CampaignSystem.dll

using System;
using System.Collections.Generic;
using TaleWorlds.SaveSystem;

#nullable disable
namespace TaleWorlds.CampaignSystem.Settlements.Locations
{
  public class AccompanyingCharacter
  {
    public LocationCharacter LocationCharacter;
    [SaveableField(2)]
    private List<Location> _disallowedLocations;

    internal static void AutoGeneratedStaticCollectObjectsAccompanyingCharacter(
      object o,
      List<object> collectedObjects)
    {
      ((AccompanyingCharacter) o).AutoGeneratedInstanceCollectObjects(collectedObjects);
    }

    protected virtual void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
    {
      collectedObjects.Add((object) this._disallowedLocations);
    }

    internal static object AutoGeneratedGetMemberValueIsFollowingPlayerAtMissionStart(object o)
    {
      return (object) ((AccompanyingCharacter) o).IsFollowingPlayerAtMissionStart;
    }

    internal static object AutoGeneratedGetMemberValue_disallowedLocations(object o)
    {
      return (object) ((AccompanyingCharacter) o)._disallowedLocations;
    }

    [SaveableProperty(1)]
    public bool IsFollowingPlayerAtMissionStart { get; private set; }

    public AccompanyingCharacter(
      LocationCharacter locationCharacter,
      bool isFollowingPlayerAtMissionStart)
    {
      this._disallowedLocations = new List<Location>();
      this.LocationCharacter = locationCharacter;
      this.IsFollowingPlayerAtMissionStart = isFollowingPlayerAtMissionStart;
    }

    public bool CanEnterLocation(Location location)
    {
      return !this._disallowedLocations.Contains(location);
    }

    public void AllowEntranceToLocations(Func<Location, bool> predicate)
    {
      foreach (Location listOfLocation in LocationComplex.Current.GetListOfLocations())
      {
        if (predicate(listOfLocation) && this._disallowedLocations.Contains(listOfLocation))
          this._disallowedLocations.Remove(listOfLocation);
      }
    }

    public void DisallowEntranceToLocations(Func<Location, bool> predicate)
    {
      foreach (Location listOfLocation in LocationComplex.Current.GetListOfLocations())
      {
        if (predicate(listOfLocation) && !this._disallowedLocations.Contains(listOfLocation))
          this._disallowedLocations.Add(listOfLocation);
      }
    }

    public void AllowEntranceToAllLocations() => this._disallowedLocations.Clear();

    public void DisallowEntranceToAllLocations()
    {
      this.AllowEntranceToAllLocations();
      this._disallowedLocations.AddRange(LocationComplex.Current.GetListOfLocations());
    }
  }
}
